/**
 * 	题型为问题+指导语 时使用
 */
export const guide = {
	data() {
		return {
			guidePress: false //指导语是否播放
		}
	},
	/**
	 * 	分割指导语和问题
	 */
	beforeMount() {
		const question = this.question.questionName.split('\n')
		this.question.questionName = question[0]
		this.question.guide = question[1]
		this.assignment = this.question
	},
	computed: {
		questionWord() {
			return this.guidePress ? this.assignment.guide : this.assignment.questionName
		}
	},
	methods: {
		/**
		 * 	播放问题
		 *  将问题转换成音频播放
		 * 	优先播放问题再播放指导语
		 * 	改变播放状态
		 */
		questionPlay: async function() {
			const data = await this.parseTextAudio({
				text: this.question.questionName,
				speaker: this.assignment.audioSpeaker ? this.assignment.audioSpeaker : null
			})
			this.dialogueAudio({
				src: data,
				start: () => {
					this.questionPress = true
					this.guidePress = false
				},
				end: async () => {
					const guide = await this.parseTextAudio({
						text: this.assignment.guide,
						speaker: this.assignment.audioSpeaker ? this.assignment.audioSpeaker : null
					})
					const timer = setTimeout(() => {
						this.dialogueAudio({
							src: guide,
							start: () => {
								this.guidePress = true
							},
							end: () => {
								this.questionPress = false
							}
						})
					}, 1000)
					this.$once('hook:beforeDestroy', function() {
						clearInterval(timer)
					})
				}
			})
		},
		/**
		 * 	暂停问题播放
		 */
		questionPause: function() {
			this.dialogueAudio({
				play: false
			})
			this.guidePress = false
			this.questionPress = false
		},
	}
}
